﻿// JavaScript Document

function menuInit(){
	
	//menu延遲收回
	TweenLite.to( $('#menu_menu'), 0, { css:{ }, onComplete:menuOutHandler, delay:2});
	
	//menu tag滑鼠事件
	$('#menuTag').mouseover(function(e){
		menuOvrHandler(e);		
	});
	
	$('#menuTag').mouseleave(function(e){
		menuOutHandler(e);		
	});
	
	//menu事件
	$('#menuTag li').mouseover(function(e) {
        menuListOvrHandler(e);
    });
	
	$('#menuTag li').mouseleave(function(e) {
        menuListOvrHandler(e);
    });
	
	$('#menuTag li').click(function(e) {
        menuClickHandler(e);
    });
	
	topMenuInit();
	topMenuAni();
	
	//TweenLite.to( $('html,body'), 2, { css:{ scrollTop:1000 },ease:Quart.easeOut});	
	
};

function menuClickHandler(e){
	
	var tarObj = e.target;	
	
	switch( $(tarObj).attr('id') ){
		case 'menu_about':
			winTopHandler( pageAboutStart );
			break;
			
		case 'menu_works':
			winTopHandler( pagePortfolioEnd - 500 );
			break;
			
		case 'menu_contact':
			winTopHandler( bodyH );
			break;
	};
	
};
//去到选择的页面
function winTopHandler( winTop ){
	
	TweenLite.to( $('html,body'), 3, { scrollTop:winTop,ease:Power1.easeOut});	
	
};


function menuListOvrHandler(e){
	
	var tarObj = e.target;
	
	switch(e.type){
		case 'mouseover':
			//$(tarObj).css({ backgroundPosition:'0px -19px' });
			TweenLite.to( $(tarObj), 0.4, { css:{ backgroundPosition:'0px -19px' },ease:Quart.easeOut});
			break;
		
		case 'mouseleave':
			//$(tarObj).css({ backgroundPosition:'0px 0px' });
			TweenLite.to( $(tarObj), 0.4, { css:{ backgroundPosition:'0px 0px' },ease:Quart.easeInOut});
			break;
	};
	
};


//menuTag收展事件
function menuOvrHandler(e){	
	TweenLite.to( $('#menuTag'), 0.5, { css:{ top:-40 }, ease:Back.easeOut});
	TweenLite.to( $('#tagLight'), 0.5, { css:{ top:35 }, ease:Back.easeOut});
	TweenLite.to( $('#menu_menu'), 0.4, { css:{ opacity:0, top:185 }, ease:Quart.easeOut});
};

function menuOutHandler(e){	
	TweenLite.to( $('#menuTag'), 0.8, { css:{ top:-170 }, ease:Elastic.easeOut});
	TweenLite.to( $('#tagLight'), 0.8, { css:{ top:165 }, ease:Elastic.easeOut});	
	TweenLite.to( $('#menu_menu'), 0.6, { css:{ opacity:1, top:185 }, ease:Quart.easeInOut});	
};


/*topMenu*/
var soundPlayer;
var soundP = true;

function topMenuInit(){
	
	$('#topMenu li').mouseover(function(e) {
        TweenLite.to( $(this), 0.1, { css:{ opacity:0.7 }, ease:Quart.easeOut});
    });
	
	$('#topMenu li').mouseleave(function(e) {
        TweenLite.to( $(this), 0.1, { css:{ opacity:1 }, ease:Quart.easeOut});
    });
	
	$('#topMenu li').click(function(e) {
        topMenuClickHandler(e);
    });

	soundPlayer = document.getElementById('music');
	soundPlayer.volume = 0.3;
	soundPlayer.play();
	
};

function topMenuClickHandler(e){
	
	var tarObj = e.target;
	
	switch( $(tarObj).attr('id') ){
		case 'fb':
			window.open('#','_blank')
			break;
			
		case 'sound':
			if( soundP == true ){
				$('#sound').addClass('sound_off');
				soundHandler('off');
				soundP = false;
			}else{
				$('#sound').removeClass('sound_off');
				soundHandler('on');
				soundP = true;
			};
			break;
	};
	
};

function soundHandler( type ){
	
	switch(type){
		case 'on':
			TweenLite.to( soundPlayer, 1, {volume:0.3, ease:Power1.easeOut });
			break;
		case 'off':
			TweenLite.to( soundPlayer, 1, {volume:0, ease:Power1.easeOut });
			break;
	};
	
};

function topMenuAni(){
	$.fn.aniBGFrameExt('#fb',31,2,0.5);
	$.fn.aniBGFrameExt('#sound',31,2,0.5);
}